import sys,os
className = sys.argv[1]

def replace_func(oldtext, newtext, oldfile, newfile):
    f=open(oldfile,'rb')
    new_file=open(newfile,'wb')#文件名以.开头的文件是隐藏文件
    for line in f.readlines():#f.xreadlines()返回一个文件迭代器，每次只从文件（硬盘）中读一行
        line = line.replace(oldtext.encode(), newtext.encode())
        line = line.replace((oldtext[0].lower() + oldtext[1:]).encode(), (newtext[0].lower() + newtext[1:]).encode())
        line = line.replace("template".encode(), newtext.lower().encode())
        line = line.replace("Template".encode(), newtext.encode())
        new_file.write(line)
    f.close()
    new_file.close()
    return

MapperName = "../src/main/java/com/example/javagd/mapper/MyTemplateMapper.java"
PojoName = "../src/main/java/com/example/javagd/pojo/MyTemplatePojo.java"
ServiceName = "../src/main/java/com/example/javagd/service/IMyTemplateService.java"
ServiceImplName = "../src/main/java/com/example/javagd/service/impl/MyTemplateServiceImpl.java"
MapperXmlName = "../src/main/resources/mappers/MyTemplateMapper.xml"
ControllerName = "../src/main/java/com/example/javagd/controller/MyTemplateController.java"

newMapperName = "../src/main/java/com/example/javagd/mapper/" + className+"Mapper.java"
newPojoName = "../src/main/java/com/example/javagd/pojo/" + className+"Pojo.java"
newServiceName = "../src/main/java/com/example/javagd/service/I" + className+"Service.java"
newServiceImplName = "../src/main/java/com/example/javagd/service/impl/" + className+"ServiceImpl.java"
newMapperXmlName = "../src/main/resources/mappers/" + className+"Mapper.xml"
newControllerName = "../src/main/java/com/example/javagd/controller/" + className + "Controller.java"

replace_func("MyTemplate", className, MapperName, newMapperName)
replace_func("MyTemplate", className, PojoName, newPojoName)
replace_func("MyTemplate", className, ServiceName, newServiceName)
replace_func("MyTemplate", className, ServiceImplName, newServiceImplName)
replace_func("MyTemplate", className, MapperXmlName, newMapperXmlName)
replace_func("MyTemplate", className, ControllerName, newControllerName)





